package com.ctshk.rpc.custom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.rpc.custom.entity.CustomizedTripScheduleCollectionTouristFee;
import com.ctshk.rpc.custom.mapper.CustomizedTripScheduleCollectionTouristFeeMapper;
import com.ctshk.rpc.custom.service.ICustomizedTripScheduleCollectionTouristFeeService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 团期代收费用旅客类型价格 服务实现类
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-21
 */
@DubboService
public class CustomizedTripScheduleCollectionTouristFeeServiceImpl extends ServiceImpl<CustomizedTripScheduleCollectionTouristFeeMapper, CustomizedTripScheduleCollectionTouristFee> implements ICustomizedTripScheduleCollectionTouristFeeService {

    @Autowired
    private CustomizedTripScheduleCollectionTouristFeeMapper tripScheduleCollectionTouristFeeMapper;

    /**
     * 根据团期和旅客类型获取代收费用金额
     *
     * @param scheduleId
     * @param mainDataId
     * @return
     */
    @Override
    public BigDecimal queryCollectionFee(Long scheduleId, Long mainDataId) {
        QueryWrapper<CustomizedTripScheduleCollectionTouristFee> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(scheduleId != null,"schedule_id",scheduleId);
        queryWrapper.eq(mainDataId != null,"tourist_type_id",mainDataId);
        List<CustomizedTripScheduleCollectionTouristFee> collectionFeeList = tripScheduleCollectionTouristFeeMapper.selectList(queryWrapper);
        if (CollectionUtils.isNotEmpty(collectionFeeList)){
            BigDecimal totalAmount = BigDecimal.ZERO;
            for (CustomizedTripScheduleCollectionTouristFee touristFee : collectionFeeList){
                if (touristFee.getTotalAmount() != null){
                    totalAmount = totalAmount.add(touristFee.getTotalAmount());
                }
            }
            return totalAmount;
        }
        return null;
    }
}
